package com.aviccxzx.smarthome.UserModule;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Window;
import android.view.WindowManager;

import com.aviccxzx.smarthome.R;
import com.aviccxzx.smarthome.fragment.GuideFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by joey on 2017/3/19.
 */

public class GuideLayFragment extends FragmentActivity {
    ViewPager viewPager_guide;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setContentView(R.layout.guide_lay_v19);
        }else {

        }
        initStatebar();
        initView();
    }

    private void initView() {
        viewPager_guide = (ViewPager) findViewById(R.id.viewPager_guide);
        List<Fragment> fragmentsList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
           Fragment fragment = new GuideFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("index",i );
            fragment.setArguments(bundle);
            fragmentsList.add(fragment);
        }
        viewPager_guide.setAdapter(new GuideAdapter(getSupportFragmentManager(),fragmentsList));
        viewPager_guide.setCurrentItem(0);
    }

    /**
     * 透明状态设置
     */
    private void initStatebar() {
        //透明状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            // Translucent status bar
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    class GuideAdapter extends FragmentPagerAdapter {

        private List<Fragment> fragmentsList = null;

        public GuideAdapter(FragmentManager fm) {
            super(fm);
        }

        public GuideAdapter(FragmentManager fm, List<Fragment> fragmentsList) {
            super(fm);
            this.fragmentsList = fragmentsList;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentsList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentsList.size();
        }

    }
}
